import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:xview/components/xNavbar.dart';
import 'package:xview/components/xSwiper.dart';
import 'package:xview/utils/dimension.dart';

class swiper extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _swiperState();
  }
}

class _swiperState extends State<swiper> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: XNavbar(
        title: 'swiper 轮播'
      ).render(context),
      body: Container(
        margin: EdgeInsets.only(top: Dimension(context).toPx(20)),
        width: Dimension(context).toVw(100),
        height: Dimension(context).toPx(150),
        child: XSwiper(
          itemCount: 3,
          loop: false,
          pagination: SwiperPagination(),
          onScroll: (metrics){
            print('${metrics.pixels},${metrics.axis}');
          },
          itemBuilder: (context,index){
            return Align(
              alignment: Alignment.topCenter,
              child: Container(
                width: Dimension(context).toPx(345),
                height: Dimension(context).toPx(150),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.all(Radius.circular(Dimension(context).toPx(16)))
                ),
                child: Center(
                  child: Text('page-${index+1}'),
                ),
              ),
            );
          },
        ),
      )
    );
  }
}
